.pragma library

// From: http://www.knmi.nl/~beekhuis/rad_proj.html
var Rp = 6356.752315;
var Re = 6378.137;


var e = Math.sqrt( 1 - Math.pow(Rp/Re, 2));

function toRad(degree) {
    return (Math.PI / 180) * degree;
}

var L0 = 0.0
var B0 = toRad(90.0);

var Bw = toRad(60.0);

var OI = 0 + 4;
var OJ = 3730 + 1;

var PX = 1.0;
var PY = -1.0;

function f(B) {
    return (1-e)*(1+e*Math.sin(B)) / ( (1+e)*(1-e*Math.sin(B)) );
}

function F(B) {
    return Math.pow(f(B),(e/2)) / Math.sqrt(1-Math.pow(e,2))
}

function R(B) {
    return 2 * Re * Math.tan(toRad(45) - B/2) * F(B);
}

function g(Bw) {
    return (1-e)*(1+e*Math.sin(Bw)) / ( (1+e)*(1-e*Math.sin(Bw)) );
}
function G(Bw) {
    return Math.pow(g(Bw),e/2) * Math.sqrt( (1-Math.pow(e*Math.sin(Bw),2)) / (1-Math.pow(e,2)) );
}

function Z(Bw) {
    return 2 * Math.tan(toRad(45)-Bw/2) * G(Bw) / Math.cos(Bw);
}


function X(B, L) {
    B = toRad(B);
    L = toRad(L);

    return R(B) / Z(Bw) * Math.sin(L-L0);
}

function Y(B, L) {
    B = toRad(B);
    L = toRad(L);

    return -R(B) / Z(Bw) * Math.cos(L-L0);
}
